<%-- 
    Document   : newService
    Created on : Jun 20, 2013, 11:14:19 AM
    Author     : Anna SAELEE
--%>

<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link type="text/css" rel="stylesheet" href="style.css"/>
        <title>List des services</title>
    </head>
    <%  Connection conn;
        Statement stmt;
        ResultSet rs, rs2;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/dormitorymanagement", "root", "root");
            stmt = conn.createStatement();%>
    <body>
        <div class="wrapper">
            <div class="header"></div>
            <div class="navigator"> <a href="#">MENU</a> > <a href="#">SUBMENU</a> 30*1000 </div>
            <div class="workspace">
                <%@include file="connect.jsp" %>
                <div class="workspace2">
                    <%
                        if (session.getAttribute("username") == null || !session.getAttribute("username").equals("admin")) {%>
                    Connectez-vous comme l'administrateur, s'il vous plaît!
                    <% } else {%>
                    <h3>Les services actuels</h3><br/>
                    <div class="workspace2-1">
                        <table align="center" width="100%" border="0">
                            <tr align="center">
                                <th>N°</th>
                                <th>Nom du type de service</th>
                            </tr>
                            <% String sql = "SELECT cid FROM category WHERE type='service'";
                                rs = stmt.executeQuery(sql);
                                if (rs.next()) {
                                    String sql2 = "SELECT cname FROM category WHERE type='service'";
                                    rs2 = stmt.executeQuery(sql2);
                                    int n = rs2.getRow();
                                    while (rs2.next()) {%>
                            <tr align="center">
                                <td><%= rs2.getRow()%></td>
                                <td><%= rs2.getString("cname")%></td>
                            </tr>
                            <% }
                            } else {%>
                            <tr><td colspan="2">Il n'y aucun type de service dans le système</td></tr>
                            <% }%>
                        </table>
                    </div><br/>
                    <h3>Créer nouveau service</h3><br/>
                    <div class="workspace2-2">
                        <form method="post" action="Enregistrer" name="newService">
                            <input type="hidden" name="typeMss" value="newService"/>
                            <table align="center" border="0" width="100%">
                                <tr>
                                    <th>Nom de service: </th>
                                    <td>
                                        <input type="text" name="serviceName"/>
                                    </td>
                                </tr>
                                <tr align="center">
                                    <td colspan="2"><br/>
                                        <input type="submit" name="createService" value="Créer nouveau service"/>
                                    </td>
                                </tr>
                            </table>
                        </form>
                    </div><br/>
                    <% }%>
                </div>
                <%@include file="sidespace.jsp" %>
            </div>
            <div class="footer"> FOOTER 80*1000 </div>
        </div>
    </body>
    <% } finally {
            out.close();
        }
    %>
</html>
